using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline.Processors;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
using Utility2DLibrary;
// TODO: replace this with the type you want to write out.
using TWrite = Utility2DLibrary.Point;

namespace UtilityContentPipelineExtension
{
    /// <summary>
    /// This class will be instantiated by the XNA Framework Content Pipeline
    /// to write the specified data type into binary .xnb format.
    ///
    /// This should be part of a Content Pipeline Extension Library project.
    /// </summary>
    [ContentTypeWriter]
    public class PointPrimitiveTypeReaderWriter : ContentTypeWriter<TWrite>
    {
        protected override void Write(ContentWriter output, TWrite value)
        {
            output.WriteObject<Vector2>(value.ToVector2());
        }

        public override string GetRuntimeReader(TargetPlatform targetPlatform)
        {
            return typeof(TWrite).AssemblyQualifiedName;
        }
    }
    public class PointPrimitiveContentReader : ContentTypeReader<TWrite>
    {
        protected override TWrite Read(ContentReader input, TWrite existingInstance)
        {
            TWrite twrite = existingInstance;
            if (twrite == null)
            {
                twrite = new TWrite();
            }
            twrite = new Utility2DLibrary.Point(input.ReadVector2());
            return twrite;
        }
    }
}
